package com.maotouying.owlsmart;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.widget.TextView;

import com.maotouying.owlsmart.LoginPage.LoginActivity;
import com.maotouying.owlsmart.SmartUtil.SystemUtil;

import java.util.Timer;
import java.util.TimerTask;

public class InitActivity extends AppCompatActivity {

    private TextView init_text_number;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_init);
        //顶部框颜色
        SystemUtil.setStatusBarColor(this, this.getResources().getColor(R.color.top_background_color));

        init_text_number = (TextView)findViewById(R.id.init_text_number);
        timer_start();

    }

    private int timer_flag =3;
    private void timer_start()
    {
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

                Message msg =new Message();
                msg.what = 1;
                msg.obj = timer_flag;
                handler.sendMessage(msg);
                timer_flag--;
                if(timer_flag < 0)
                {
                    timer_flag = 3;
                    timer.cancel();
                    Intent intent = new Intent(InitActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
            }
        }, 3, 1000);
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event){
        if(keyCode== KeyEvent.KEYCODE_BACK)
            return true;
        return super.onKeyDown(keyCode, event);
    }//屏蔽返回键

    private Handler handler =new Handler()
    {
        public void handleMessage(Message msg)
        {
            if(msg.what == 1)
            {
                init_text_number.setText(""+msg.obj);
            }
        }
    };

}